<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>智慧社区后台</title>
<meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
<link rel="stylesheet" href="${pageContext.request.contextPath}/plugins/bootstrap/css/bootstrap.min.css">
<link rel="stylesheet" href="${pageContext.request.contextPath}/css/AdminLTE.min.css">
<link rel="stylesheet" href="${pageContext.request.contextPath}/plugins/bootstrap-switch/css/bootstrap-switch.min.css">
</head>
<style>
</style>
<body id="body" style="padding-bottom: 90px; background-color: #ECF0F5;">
	<div class="modal-content">
		<div class="modal-body">
			<div class="input-group">
				<span class="input-group-addon">车牌号：</span>
				<div class="input-group-btn">
					<select class="form-control" style="width: 61px;" id="provincialCapital">

					</select>
				</div>
				<input type="text" class="form-control" id="licensePlate" onkeyup="this.value=this.value.toUpperCase()">
			</div>
			<br />
			<div class="input-group">
				<span class="input-group-addon">车主电话：</span> <input type="text" class="form-control" id="tel">
			</div>
			<br />
			<div class="input-group">
				<span class="input-group-addon">使用年限：</span> <input type="text" class="form-control" id="timeLimit" disabled="disabled">
			</div>
			<br />
			<div class="input-group">
				<span class="input-group-addon">金额：</span> <input type="text" class="form-control" id="sellPrice" disabled="disabled">
			</div>
			<br />
			<div class="input-group">
				<span class="input-group-addon">来源：</span> <select class="form-control" id="source">
					<option value="">请选择...</option>
					<option value="支付宝">支付宝</option>
					<option value="微信">微信</option>
					<option value="银行卡">银行卡</option>
					<option value="现金">现金</option>
				</select>
			</div>
		</div>
	</div>
</body>
<script src="${pageContext.request.contextPath}/plugins/jQuery/jquery-2.2.3.min.js"></script>
<script src="${pageContext.request.contextPath}/plugins/bootstrap/js/bootstrap.min.js"></script>
<script src="${pageContext.request.contextPath}/plugins/bootstrap-switch/js/bootstrap-switch.min.js"></script>
<!-- layer -->
<script src="${pageContext.request.contextPath}/plugins/layer/2.4/layer.js"></script>
<script src="${pageContext.request.contextPath}/js/ajaxfileupload.js"></script>
<script src="${pageContext.request.contextPath}/js/date.js"></script>

<!-- kindeditor 编辑器 -->
<script charset="utf-8" src="${pageContext.request.contextPath}/kindeditor-4.1.10/kindeditor.js"></script>
<script charset="utf-8" src="${pageContext.request.contextPath}/kindeditor-4.1.10/lang/zh_CN.js"></script>
<script>
	var lock = false;
	var id = "${map['id']}";
	var index = parent.layer.getFrameIndex(window.name);

	$(function() {
		var html = '';
		var mycars = [ "京", "沪", "浙", "苏", "粤", "鲁", "晋", "冀", "豫", "川", "渝",
				"辽", "吉", "黑", "皖", "鄂", "津", "贵", "云", "桂", "琼", "青", "新",
				"藏", "蒙", "宁", "甘", "陕", "闽", "赣", "湘" ];
		for (var i = 0; i < mycars.length; i++) {
			html += "<option value='"+mycars[i]+"'>" + mycars[i] + "</option>";
		}
		$("#provincialCapital").html(html);
		$.ajax({
			url : "${pageContext.request.contextPath}/selectParkingSpaceById",
			type : "post",
			data : {
				id : id
			},
			dataType : "json",
			success : function(map) {
				var parkingSpace = map['parkingSpace'];
				$("#licensePlate").val(parkingSpace.licensePlate);
				$("#tel").val(parkingSpace.tel);
				$("#timeLimit").val(parkingSpace.timeLimit);
				$("#sellPrice").val(parkingSpace.sellPrice);
			}
		});
	});
	
	function insertCar() {
		var licensePlate = $("#licensePlate").val();
		var tel = $("#tel").val();
		var source = $("#source").val();
		var phone = /^1([38]\d|5[0-35-9]|7[3678])\d{8}$/;
		if (licensePlate == '' || tel == '' || source == '') {
			layer.alert("请填写数据!");
			lock = false;
			return;
		}
		if (phone.test(tel) == false) {
			layer.alert("手机输入不合法!");
			that.lock = false;
			return;
		}
		var yue = accMul(parseInt($("#timeLimit").val()), 12);
		var price = parseFloat($("#sellPrice").val());
		layer.confirm("是否确认缴费,缴费金额为" + price.toFixed(2) + "?", function(index) {
		$.ajax({
			url : '${pageContext.request.contextPath}/insertPropertyBill',
			type : "post",
			data : {
				payObjectId : id,
				payProject : "车位费",
				price : price.toFixed(2),
				source : source,
				payMethod : "线下付款",
				tel : tel,
				yue : yue,
				licensePlate : $("#provincialCapital").val() + licensePlate,
				state : '2'
			},
			dataType : "json",
			success : function(data) {
				var result = data['result'];
				if (result == 1) {
					layer.msg('操作成功!', {
						icon : 1,
						time : 800
					});
					setTimeout(function() {
						parent.querry();
						parent.layer.close(parent.layer
								.getFrameIndex(window.name));
					}, 1000);
				} else {
					layer.msg('操作失败!', {
						icon : 2,
						time : 800
					});
					lock = false;
				}
			}
		});
		});
		lock = false;
	}

	function accMul(arg1, arg2) {
		if (isNaN(arg1)) {
			arg1 = 0;
		}
		if (isNaN(arg2)) {
			arg2 = 0;
		}
		arg1 = Number(arg1);
		arg2 = Number(arg2);

		var m = 0, s1 = arg1.toString(), s2 = arg2.toString();
		try {
			m += s1.split(".")[1].length;
		} catch (e) {
		}
		try {
			m += s2.split(".")[1].length;
		} catch (e) {
		}
		return Number(s1.replace(".", "")) * Number(s2.replace(".", ""))
				/ Math.pow(10, m);
	}

	// 给Number类型增加一个mul方法，调用起来更加方便。
	Number.prototype.mul = function(arg) {
		return accMul(this, arg);
	};

	//添加
	function insert() {
		if (!lock) {
			insertCar();
		}
	}
</script>
</html>
